VERSION 5.00
Object = "{A8E5842E-102B-4289-9D57-3B3F5B5E15D3}#13.2#0"; "CODEJO~3.OCX"
Begin VB.Form frmPermisos 
   Caption         =   "Form1"
   ClientHeight    =   6225
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8205
   LinkTopic       =   "Form1"
   ScaleHeight     =   6225
   ScaleWidth      =   8205
   StartUpPosition =   2  'CenterScreen
   Begin XtremeSuiteControls.PushButton cancelarButton 
      Height          =   600
      Left            =   5280
      TabIndex        =   4
      Top             =   5400
      Width           =   1545
      _Version        =   851970
      _ExtentX        =   2725
      _ExtentY        =   1058
      _StockProps     =   79
      Caption         =   "&Cancelar"
      Appearance      =   6
   End
   Begin XtremeSuiteControls.PushButton guardarButton 
      Height          =   600
      Left            =   1200
      TabIndex        =   3
      Top             =   5400
      Width           =   1545
      _Version        =   851970
      _ExtentX        =   2725
      _ExtentY        =   1058
      _StockProps     =   79
      Caption         =   "&Guardar"
      Appearance      =   6
   End
   Begin XtremeSuiteControls.GroupBox GroupBox1 
      Height          =   3975
      Left            =   240
      TabIndex        =   1
      Top             =   1200
      Width           =   7695
      _Version        =   851970
      _ExtentX        =   13573
      _ExtentY        =   7011
      _StockProps     =   79
      Caption         =   "Permisos"
      Appearance      =   6
      Begin XtremeSuiteControls.ListView ListaPermisosAsignados 
         Height          =   3135
         Left            =   4320
         TabIndex        =   8
         Top             =   600
         Width           =   3135
         _Version        =   851970
         _ExtentX        =   5530
         _ExtentY        =   5530
         _StockProps     =   77
         BackColor       =   -2147483643
         Checkboxes      =   -1  'True
         View            =   3
         FullRowSelect   =   -1  'True
         Appearance      =   6
         UseVisualStyle  =   0   'False
      End
      Begin XtremeSuiteControls.ListView ListaPermisosAsignar 
         Height          =   3135
         Left            =   240
         TabIndex        =   5
         Top             =   600
         Width           =   3135
         _Version        =   851970
         _ExtentX        =   5530
         _ExtentY        =   5530
         _StockProps     =   77
         BackColor       =   -2147483643
         Checkboxes      =   -1  'True
         View            =   3
         FullRowSelect   =   -1  'True
         FlatScrollBar   =   -1  'True
         Appearance      =   6
         UseVisualStyle  =   0   'False
      End
      Begin VB.CheckBox AsignadosCheck 
         Caption         =   "Marcar Todo"
         Height          =   375
         Left            =   4320
         TabIndex        =   10
         Top             =   240
         Width           =   1815
      End
      Begin VB.CheckBox AsignarCheck 
         Caption         =   "Marcar Todo"
         Height          =   375
         Left            =   240
         TabIndex        =   9
         Top             =   240
         Width           =   1695
      End
      Begin XtremeSuiteControls.PushButton derButton 
         Height          =   615
         Left            =   3600
         TabIndex        =   7
         Top             =   2040
         Width           =   495
         _Version        =   851970
         _ExtentX        =   873
         _ExtentY        =   1085
         _StockProps     =   79
         Caption         =   "<"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Appearance      =   5
      End
      Begin XtremeSuiteControls.PushButton izqButton 
         Height          =   615
         Left            =   3600
         TabIndex        =   6
         Top             =   1080
         Width           =   495
         _Version        =   851970
         _ExtentX        =   873
         _ExtentY        =   1085
         _StockProps     =   79
         Caption         =   ">"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Appearance      =   5
      End
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   240
      TabIndex        =   2
      Top             =   120
      Width           =   7695
   End
   Begin VB.Label userLabel 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   13.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000C0&
      Height          =   540
      Left            =   240
      TabIndex        =   0
      Top             =   600
      Width           =   7770
   End
End
Attribute VB_Name = "frmPermisos"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public id_usuario As Integer
Public nombreApellido_usuario As String
Public nombre_usuario As String

Private Sub cancelarButton_Click()
Unload Me
End Sub

Private Sub AgregarCheckMarcarDesmarcar()
If (ListaPermisosAsignar.ListItems.Count = 0) Then
    AsignarCheck.Visible = False
Else
    AsignarCheck.Visible = True
    AsignarCheck.Value = False
End If

If (ListaPermisosAsignados.ListItems.Count = 0) Then
AsignadosCheck.Visible = False
Else
AsignadosCheck.Visible = True
AsignadosCheck.Value = False
End If




End Sub
Private Sub AsignadosCheck_Click()
Dim item As ListItem
 
If (AsignadosCheck.Value = 1) Then

AsignadosCheck.Caption = "Desmarcar Todo"

    For i = 1 To ListaPermisosAsignados.ListItems.Count
    ListaPermisosAsignados.ListItems.item(i).Selected = True
     ListaPermisosAsignados.SelectedItem.Checked = True
        
    Next
    
Else

AsignadosCheck.Caption = "Marcar Todo"
For i = 1 To ListaPermisosAsignados.ListItems.Count
    ListaPermisosAsignados.ListItems.item(i).Selected = True
    ListaPermisosAsignados.SelectedItem.Checked = False
 
Next
End If

End Sub



Private Sub AsignarCheck_Click()
Dim item As ListItem
 
If (AsignarCheck.Value = 1) Then

AsignarCheck.Caption = "Desmarcar Todo"

    For i = 1 To ListaPermisosAsignar.ListItems.Count
    ListaPermisosAsignar.ListItems.item(i).Selected = True
     ListaPermisosAsignar.SelectedItem.Checked = True
        
    Next
    
Else

AsignarCheck.Caption = "Marcar Todo"
For i = 1 To ListaPermisosAsignar.ListItems.Count
    ListaPermisosAsignar.ListItems.item(i).Selected = True
    ListaPermisosAsignar.SelectedItem.Checked = False
 
Next
End If

End Sub
'Private Sub ListaPermisosAsignados_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'
'
'   ' si no hay seleccionado sale
'   If ListaPermisosAsignados.SelectedItem Is Nothing Then Exit Sub
'ListaPermisosAsignados.ToolTipText = ListaPermisosAsignados.SelectedItem
'
'
'End Sub
 
'Private Sub ListaPermisosAsignar_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'
'
'   ' si no hay seleccionado sale
'   If ListaPermisosAsignar.SelectedItem Is Nothing Then Exit Sub
'ListaPermisosAsignar.ToolTipText = ListaPermisosAsignar.SelectedItem
'
'
'End Sub


Private Sub Form_Load()
Dim queryPermiso As String
Dim queryNoPermisoAsginados As String
Dim rsPermisoAsignados As ADODB.Recordset
Dim rsPermisoAsignar As ADODB.Recordset

setColorFormControls Me
setIconButton guardarButton, GUARDAR_BUTTON
setIconButton cancelarButton, CANCELAR_BUTTON


agregarColumnasListaPermisosAsignados
agregarColumnasListaPermisosAsignar

userLabel.Caption = nombreApellido_usuario
Label2.Caption = "Usuario: " & nombre_usuario

queryNoPermisoAsginados = "select descripcion,id from permisos where id IN (select id_permiso from permisos_usuarios where id_usuario =" & id_usuario & " )"
Set rsPermisoAsignados = cn.ejecutarQuery_recordSet(queryNoPermisoAsginados)

queryPermisoAsginar = "select descripcion,id from permisos where id NOT IN (select id_permiso from permisos_usuarios where id_usuario =" & id_usuario & " )"
Set rsPermisoAsignar = cn.ejecutarQuery_recordSet(queryPermisoAsginar)

cargarListaPermisosAsignados rsPermisoAsignados
cargarListaPermisosAsignar rsPermisoAsignar

'Elimina la columna ID de los dos ListView
ListaPermisosAsignados.ColumnHeaders.Remove 2
ListaPermisosAsignar.ColumnHeaders.Remove 2
AgregarCheckMarcarDesmarcar

End Sub

Private Sub agregarColumnasListaPermisosAsignar()
    ListaPermisosAsignar.ColumnHeaders.Add , , "Permisos a Asignar", ListaPermisosAsignar.Width
    ListaPermisosAsignar.ColumnHeaders.Add , , "id", 0
    
End Sub

Private Sub agregarColumnasListaPermisosAsignados()
    ListaPermisosAsignados.ColumnHeaders.Add , , "Permisos Asignados", ListaPermisosAsignados.Width
    ListaPermisosAsignados.ColumnHeaders.Add , , "id", 0
        
End Sub

Private Sub cargarListaPermisosAsignar(rsPermisosAsignar As ADODB.Recordset)

If rsPermisosAsignar.RecordCount > 0 Then

    While Not rsPermisosAsignar.EOF
    
        Set item = ListaPermisosAsignar.ListItems.Add(, , rsPermisosAsignar!Descripcion)
         item.SubItems(1) = rsPermisosAsignar!Id
         rsPermisosAsignar.MoveNext
    Wend
rsPermisosAsignar.Close
End If
End Sub

Private Sub cargarListaPermisosAsignados(rsPermisosAsignados As ADODB.Recordset)

If rsPermisosAsignados.RecordCount > 0 Then
    While Not rsPermisosAsignados.EOF
    
        Set item = ListaPermisosAsignados.ListItems.Add(, , rsPermisosAsignados!Descripcion)
         item.SubItems(1) = rsPermisosAsignados!Id
    
        rsPermisosAsignados.MoveNext
    Wend
rsPermisosAsignados.Close
End If

End Sub

Private Sub guardarButton_Click()

Dim query As String
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim Id As Integer

'If (ListaPermisosAsignados.ListItems.Count = 0) Then
'Unload Me
'    Exit Sub
'End If

query = "Delete from permisos_usuarios where id_usuario=" & id_usuario
If cn.ejecutarQuery_boolean(query) = False Then Exit Sub

For i = 1 To ListaPermisosAsignados.ListItems.Count
                   
        Id = ListaPermisosAsignados.ListItems(i).SubItems(1)
        query = "Insert into permisos_usuarios (id_usuario,id_permiso) values (" & id_usuario & "," & Id & ")"
        
        If cn.ejecutarQuery_boolean(query) = False Then
         Call MsgBox("Se Produjo un error al grabar los permisos", vbInformation)
            Exit Sub
        
        End If
Next i

         Call MsgBox("Se ha grabado correctamente", vbInformation)
         Unload Me
End Sub
Private Sub izqButton_Click()

  Dim i As Integer

      With ListaPermisosAsignar

            For i = ListaPermisosAsignar.ListItems.Count To 1 Step -1
                If .ListItems(i).Checked Then
                With ListaPermisosAsignados.ListItems.Add
                    .Text = ListaPermisosAsignar.ListItems(i).Text
                    .SubItems(1) = ListaPermisosAsignar.ListItems(i).SubItems(1)
                 End With
                    .ListItems.Remove (i)
                 End If
            Next
      End With
AgregarCheckMarcarDesmarcar
End Sub

Private Sub derButton_Click()

  Dim i As Integer

      With ListaPermisosAsignados

            For i = ListaPermisosAsignados.ListItems.Count To 1 Step -1
                If .ListItems(i).Checked Then
                    With ListaPermisosAsignar.ListItems.Add
                        .Text = ListaPermisosAsignados.ListItems(i).Text
                        .SubItems(1) = ListaPermisosAsignados.ListItems(i).SubItems(1)
                     End With
                        .ListItems.Remove (i)
                 End If
            Next
      End With
AgregarCheckMarcarDesmarcar
End Sub

